package cn.gson.springmvc.model.pojos;

import javax.persistence.*;
import java.sql.Date;
import java.util.Collection;
import java.util.Objects;

@Entity
public class Presc {
    private int prescId;
    private Date prescTime;
    private String prescMes;
    private User userByUserId;
    private Collection<Prescriptiondetails> prescriptiondetailsByPrescId;

    @Id
    @Column(name = "presc_id", nullable = false)
    public int getPrescId() {
        return prescId;
    }

    public void setPrescId(int prescId) {
        this.prescId = prescId;
    }

    @Basic
    @Column(name = "presc_time", nullable = true)
    public Date getPrescTime() {
        return prescTime;
    }

    public void setPrescTime(Date prescTime) {
        this.prescTime = prescTime;
    }

    @Basic
    @Column(name = "presc_mes", nullable = true, length = 10)
    public String getPrescMes() {
        return prescMes;
    }

    public void setPrescMes(String prescMes) {
        this.prescMes = prescMes;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Presc presc = (Presc) o;
        return prescId == presc.prescId &&
                Objects.equals(prescTime, presc.prescTime) &&
                Objects.equals(prescMes, presc.prescMes);
    }

    @Override
    public int hashCode() {
        return Objects.hash(prescId, prescTime, prescMes);
    }

    @ManyToOne
    @JoinColumn(name = "user_id", referencedColumnName = "user_id")
    public User getUserByUserId() {
        return userByUserId;
    }

    public void setUserByUserId(User userByUserId) {
        this.userByUserId = userByUserId;
    }

    @OneToMany(mappedBy = "prescByPrescId")
    public Collection<Prescriptiondetails> getPrescriptiondetailsByPrescId() {
        return prescriptiondetailsByPrescId;
    }

    public void setPrescriptiondetailsByPrescId(Collection<Prescriptiondetails> prescriptiondetailsByPrescId) {
        this.prescriptiondetailsByPrescId = prescriptiondetailsByPrescId;
    }
}
